package com.huaruan.youdi.views.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.huaruan.youdi.R;
import com.huaruan.youdi.utils.StringUtils;


public class BaseDialog extends Dialog {
    TextView tv_title, tv_content;
    Button bt_left, bt_right;
    View line;
    private View contentView;

    public BaseDialog(Context context) {
        super(context, R.style.dialog);
        init();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(contentView);
        setCanceledOnTouchOutside(false);
        setCancelable(true);
    }

    private void init() {
        contentView = View.inflate(getContext(), R.layout.dialog, null);
        tv_title = (TextView) contentView.findViewById(R.id.dialogTitle);
        line = contentView.findViewById(R.id.dialogLine);
        tv_content = (TextView) contentView.findViewById(R.id.dialogContent);
        bt_left = (Button) contentView.findViewById(R.id.dialogLeftButton);
        bt_right = (Button) contentView.findViewById(R.id.dialogRightButton);
    }

    public BaseDialog setTitle(String title) {
        if (StringUtils.isEmpty(title)) {
            tv_title.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
        } else {
            tv_title.setVisibility(View.VISIBLE);
            line.setVisibility(View.VISIBLE);
            tv_title.setText(title);
        }
        return this;
    }

    public BaseDialog setContent(String content) {
        tv_content.setText(content);
        return this;
    }

    public BaseDialog setLeftButtonText(String text) {
        if (StringUtils.isEmpty(text)) {
            bt_left.setVisibility(View.GONE);
        } else {
            bt_left.setVisibility(View.VISIBLE);
            bt_left.setText(text);
        }
        return this;
    }

    public BaseDialog setRightButtonText(String text) {
        if (StringUtils.isEmpty(text)) {
            bt_right.setVisibility(View.GONE);
        } else {
            bt_right.setVisibility(View.VISIBLE);
            bt_right.setText(text);
        }
        return this;
    }

    public BaseDialog setLeftButtonListener(View.OnClickListener onClickListener) {
        bt_left.setOnClickListener(onClickListener);
        return this;
    }

    public BaseDialog setRightButtonListener(View.OnClickListener onClickListener) {
        bt_right.setOnClickListener(onClickListener);
        return this;
    }
}
